/**
 * 
 */
package No201_300.No201_210.RemoveLinkedListElements_203;


/**
 * @author 李敬
 *
 */
public class Solution {
	
    public static ListNode removeElements(ListNode head, int val) {
    	ListNode l1 = new ListNode(0);
    	l1.next = head;
    	ListNode result = l1;
    	while (l1.next != null) {
			if (l1.next.val == val) {
				l1.next = l1.next.next;
			}
			else {
				l1 = l1.next;
			}
		}
    	
    	return result.next;
    }

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		ListNode l10 = new ListNode(1);
		ListNode l11 = new ListNode(3);
		ListNode l12 = new ListNode(5);
		ListNode l13 = new ListNode(6);
		ListNode l14 = new ListNode(7);
		ListNode l15 = new ListNode(8);
		ListNode l16 = new ListNode(6);
		ListNode l17 = new ListNode(10);
		l10.next = l11;l11.next = l12;l12.next = l13;l13.next = l14;l14.next = l15;
		l15.next = l16;l16.next = l17;
		l10 = removeElements(l10, 1);
		while (l10!=null) {
			System.out.println(l10.val);
			l10 = l10.next;
		}
	}

}

/**
 * Definition for singly-linked list.
 */
class ListNode {
	int val;
	ListNode next;

	ListNode(int x) {
		val = x;
	}
}
